define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Productextent, $window, $timeout,GoPage) {
		$scope.isLoad = false; //可以加载
		$scope.from_type = 1;
		$scope.input = new Object();
		$scope.input.nPage = 1;
		$scope.datas = new Object();
		//画面加载
		$scope.$on('$ionicView.afterEnter', function() {
			//动态设置高度
			var all = $window.innerHeight;
			//计算滚动条
			$scope.myObj = {
				"height": all - 88 + "px"
			};
			$scope.init_data();
		}, false);
		
		//加载数据
		$scope.init_data = function(){
			Productextent.productextent_list(1,function(data){
				if(data!=null)
				$scope.datas = data;
				else
				$scope.datas = new Object();
				$scope.input.nPage = 1;
			})
		}

//		$scope.activeTab = function(index) {
//			$scope.selectTab = index;
//			$ionicSlideBoxDelegate.$getByHandle('tab-handle').slide(index);
//		};
//		$scope.slideChanged = function(index) {
//			//手指滑动
//			$scope.selectTab = index;
//			if (index == 0) {
//				$scope.from_type = 1;
//			} else if (index == 1) {
//				$scope.from_type = 3;
//			} else {
//				$scope.from_type = 2;
//			}
//			Productextent.getlist($scope.from_type, 1, function(data){
//				$scope.listData = data;
//			});
//			//内容刷新
//			$ionicSlideBoxDelegate.$getByHandle('tab-handle').update();
//		};

		//下拉刷新 判断哪个模块进行刷新
		$scope.doRefresh = function() {
			$scope.isLoad = true;
			Productextent.productextent_list(1,function(data){
				if(data!=null)
				$scope.datas = data;
				else
				$scope.datas = new Object();
				$scope.input.nPage = 1;
			},function(){
				$scope.$broadcast('scroll.refreshComplete');
				$timeout(function() {
				$scope.isLoad = false;
			}, 1500);
			})
			
		};
		//加载更多
		$scope.doRefreshMore = function() {
			$scope.isLoad  = true;
			Productextent.productextent_list($scope.input.nPage+1,function(data){
				if(data!=null){
					if($scope.datas.act!=undefined){
						$scope.datas.act = $scope.datas.act.concat(data.act);
						$scope.input.nPage +=1;
					}else{
						$scope.datas = data;
						$scope.input.nPage = 1;
					}
				}
			},function(){
				$scope.$broadcast('scroll.infiniteScrollComplete');
				$timeout(function() {
				$scope.isLoad = false;
			}, 1500);
			})
			
		};
		
		$scope.onshow_detial = function(act_id){
			GoPage.go_states("productextentdetail",{
				'act_id':act_id
			});
		}
	}

	controller.$inject = ['$scope', 'Productextent', '$window', '$timeout','GoPage'];

	return app.registerController("productextentctrl",controller);
});